package com.carkeeper.order.controller;


import com.carkeeper.entity.PageResult;
import com.carkeeper.entity.Result;
import com.carkeeper.entity.StatusCode;
import com.carkeeper.order.pojo.Bill;
import com.carkeeper.order.service.BillService;
import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/bill")
@Api("账单查询接口api")
@CrossOrigin
public class BillController {

    @Autowired
    private BillService billService;

    /**
     * 服务商账单分页查询
     * @param searchMap 条件查询
     * @param page      当前页码
     * @param pageSize  每页显示条数
     * @return
     */
    @GetMapping("/{page}/{pageSize}")
    @ApiOperation("服务商账单分页查询")
    @ApiImplicitParam(name = "searchMap",value = "条件",required = false)
    public PageResult billPage(@RequestParam(required = false) Map<String, Object> searchMap, @PathVariable("page") Integer page, @PathVariable("pageSize") Integer pageSize) {
        Page<Bill> pageList = billService.billPage(searchMap, page, pageSize);
        return new PageResult(pageList.getTotal(), pageList.getResult());
    }

    /**
     * 根据账单编号查询账单详情
     *
     * @param code
     * @return
     */
    @GetMapping("/selectBillByCode")
    @ApiOperation("根据账单编号查询账单详情")
    public Result selectBillByCode(String code) {
        return billService.selectBillByCode(code);
    }

    /**
     * 分页加条件查询所有未支付的账单
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/serviceBill/{page}/{pageSize}")
    @ApiOperation("分页加条件查询所有未支付的账单")
    @ApiImplicitParam(name = "searchMap",value = "条件",required = false)
    public Result serviceBill(@RequestParam(required = false) Map<String,Object> searchMap,@PathVariable("page") Integer page, @PathVariable("pageSize") Integer pageSize) {
        Page<Bill> pageList = billService.serviceBill(searchMap,page, pageSize);
        return new Result(true, StatusCode.OK, "查询成功", pageList);
    }

    /**
     * 条件查询
     * @param searchMap
     * @return
     */
    @PostMapping("/selectBill")
    @ApiOperation("条件查询")
    public Result selectBill(@RequestBody Map<String, Object> searchMap) {
        List<Bill> bills = billService.selectBill(searchMap);
        return new Result(true, StatusCode.OK, "查询成功", bills);
    }

    /**
     * 支付账单
     *
     * @param codeList
     * @return
     */
    @GetMapping("/selectCode")
    @ApiOperation("支付账单")
    public Result selectCode(@RequestParam List<String> codeList) {
        Map map = billService.selectCode(codeList);
        return new Result(true, StatusCode.OK, "查询成功", map);
    }

    /**
     * 取消支付账单
     * @param code
     * @param storeId
     * @return
     */
    @GetMapping("/deleteBill")
    @ApiOperation("取消支付账单")
    public Result deleteBill(String code,Integer storeId) {
        Map map = billService.deleteBill(code, storeId);
        return new Result(true, StatusCode.OK, "查询成功", map);
    }
}
